<template>
  <div class="container">
    <el-form
      :model="formInline"
      label-width="140px"
      @keyup.enter.native="search"
    >
      <el-row>
        <el-col :span="6">
          <el-form-item :label="$t('m.strategy.wavetemplate') + $t('m.name')">
            <el-input
              maxlength="20"
              show-word-limit
              v-model="formInline.name"
              placeholder
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" align="right">
          <el-button
            type="primary"
            @click="search"
            v-if="hasPermission('search')"
            >{{ $t("m.query") }}</el-button
          >
          <el-button type="primary" @click="add" v-if="hasPermission('add')">{{
            $t("m.add")
          }}</el-button>
        </el-col>
      </el-row>
    </el-form>
    <el-table
      ref="table"
      stripe
      empty-text
      fits
      v-loading="tableLoading"
      class="table-wrap single-select-table"
      :data="tableData"
      :row-style="tableRowStyle"
      :row-class-name="tableRowClassName"
      @row-click="rowClick"
      @selection-change="handleSingleSelectionChange"
    >
      <el-table-column
        align="center"
        type="index"
        :label="$t('m.index')"
        width="100"
      ></el-table-column>
      <el-table-column
        align="center"
        prop="wavetemplatename"
        :label="$t('m.strategy.wavetemplate') + $t('m.name')"
      >
        <template slot-scope="scope">
          <template v-if="hasPermission('table-wavetemplatename')">
            <el-button @click.stop="open(scope.row)" type="text">{{
              scope.row.wavetemplatename
            }}</el-button>
          </template>
          <template v-else>{{ scope.row.wavetemplatename }}</template>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="remark"
        :label="$t('m.strategy.description')"
      ></el-table-column>
      <el-table-column align="center" prop="state" :label="$t('m.state')">
        <template slot-scope="scope">{{
          scope.row.state ? $t("m.started") : $t("m.stopped")
        }}</template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="creator"
        :label="$t('m.creator')"
      ></el-table-column>
      <el-table-column
        align="center"
        prop="createdate"
        :label="$t('m.createdate')"
      ></el-table-column>
      <el-table-column width="180" align="center" :label="$t('m.operation')">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.state && hasPermission('table-edit')"
            @click.stop="edit(scope.row)"
            size="mini"
            type="primary"
            >{{ $t("m.edit") }}</el-button
          >
          <el-button
            v-if="hasPermission('table-edit')"
            :type="scope.row.state ? 'primary' : ''"
            size="mini"
            @click.stop="
              changeState(
                scope.row.wavetemplateid,
                scope.$index,
                (scope.row.state + 1) % 2
              )
            "
            >{{ scope.row.state ? $t("m.stop") : $t("m.start") }}</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="sizes, prev, pager, next, jumper"
      :page-sizes="pageSizeList"
      :page-size="rowSize"
      :current-page="page"
      :total="totalRows"
      @current-change="currentChangeInitFn"
      @size-change="handleSizeChangeInitFn"
    ></el-pagination>
    <el-dialog
      :close-on-click-modal="false"
      width="1000px"
      :title="title"
      :visible.sync="dialogFormVisible"
      @close="close"
    >
      <div v-loading="popLoading">
        <el-form :rules="ruleForm" ref="refForm" size="mini" :model="formData">
          <el-form-item
            :label="$t('m.strategy.wavetemplate') + $t('m.name')"
            :label-width="formLabelWidth"
            prop="wavetemplateDto.wavetemplatename"
            align="left"
          >
            <el-input
              maxlength="20"
              show-word-limit
              :disabled="isdisabled"
              size="mini"
              v-model="formData.wavetemplateDto.wavetemplatename"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('m.page.warehouse')"
            :label-width="formLabelWidth"
            prop="warehouses"
            align="left"
          >
            <el-select
              :disabled="isdisabled"
              clearable
              filterable
              v-model="formData.warehouses"
              multiple
              :placeholder="$t('m.choose')"
            >
              <el-option
                v-for="(item, index) in warehouseList"
                :key="'warehouse' + index"
                :label="item.warehousename"
                :value="item.warehouseid"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            :label="$t('m.strategy.orderquantity')"
            :label-width="formLabelWidth"
            prop="wavetemplateDto.orderquantity"
            align="left"
          >
            <el-input
              @input="positiveInt('orderquantity')"
              :disabled="isdisabled"
              maxlength="10"
              show-word-limit
              size="mini"
              v-model.number="formData.wavetemplateDto.orderquantity"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('m.strategy.description')"
            :label-width="formLabelWidth"
            prop="wavetemplateDto.remark"
            align="left"
          >
            <el-input
              :disabled="isdisabled"
              maxlength="100"
              show-word-limit
              type="textarea"
              size="mini"
              v-model="formData.wavetemplateDto.remark"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-divider content-position="center">{{
            $t("m.strategy.filter")
          }}</el-divider>
          <el-row :gutter="30">
            <el-col :span="12">
              <el-form-item
                :label="$t('m.in.consignor')"
                :label-width="formLabelWidth"
                prop="consignors"
                align="left"
              >
                <el-select
                  :disabled="isdisabled"
                  clearable
                  filterable
                  v-model="consignors"
                  multiple
                  :placeholder="$t('m.choose')"
                >
                  <el-option
                    v-for="(item, index) in consignorList"
                    :key="'consignor' + index"
                    :label="item.consignorname"
                    :value="item.consignorid"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                :label="$t('m.out.shopname')"
                :label-width="formLabelWidth"
                prop="shops"
                align="left"
              >
                <el-select
                  :disabled="isdisabled"
                  clearable
                  filterable
                  v-model="shops"
                  multiple
                  :placeholder="$t('m.choose')"
                >
                  <el-option
                    v-for="(item, index) in shopList"
                    :key="'shop' + index"
                    :label="item.shopname"
                    :value="item.shopid"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="30">
            <el-col :span="12">
              <el-form-item
                :label="$t('m.strategy.payment')"
                :label-width="formLabelWidth"
                prop="wavetemplateDto.payment"
                align="left"
              >
                <el-select
                  :disabled="isdisabled"
                  clearable
                  v-model="formData.wavetemplateDto.payment"
                  :placeholder="$t('m.choose')"
                >
                  <el-option
                    v-for="(item, index) in payList"
                    :key="'pay' + index"
                    :label="item.label"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                :label="$t('m.strategy.platform')"
                :label-width="formLabelWidth"
                prop="wavetemplateDto.platform"
                align="left"
              >
                <el-select
                  :disabled="isdisabled"
                  clearable
                  v-model="formData.wavetemplateDto.platform"
                  :placeholder="$t('m.choose')"
                >
                  <el-option
                    v-for="(item, index) in platformList"
                    :key="'platform' + index"
                    :label="item.label"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="30">
            <el-col :span="12">
              <el-form-item
                :label="$t('m.strategy.highvalue')"
                :label-width="formLabelWidth"
                prop="wavetemplateDto.highvalue"
                align="left"
              >
                <el-select
                  :disabled="isdisabled"
                  clearable
                  v-model="formData.wavetemplateDto.highvalue"
                  :placeholder="$t('m.choose')"
                >
                  <el-option
                    v-for="(item, index) in highvalueList"
                    :key="'highvalue' + index"
                    :label="item.label"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                :label="$t('m.out.ordertype')"
                :label-width="formLabelWidth"
                prop="wavetemplateDto.ordertype"
                align="left"
              >
                <el-select
                  :disabled="isdisabled"
                  clearable
                  v-model="formData.wavetemplateDto.ordertype"
                  :placeholder="$t('m.choose')"
                >
                  <el-option
                    v-for="(item, index) in ordertypeList"
                    :key="'ordertype' + index"
                    :label="item.label"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="30">
            <el-col :span="12">
              <el-form-item
                :label="$t('m.out.provincename')"
                :label-width="formLabelWidth"
                prop="regions"
                align="left"
              >
                <el-select
                  :disabled="isdisabled"
                  clearable
                  filterable
                  v-model="regions"
                  multiple
                  :placeholder="$t('m.choose')"
                >
                  <el-option
                    v-for="(item, index) in provinceList"
                    :key="'province' + index"
                    :label="item.regionname"
                    :value="item.regionid"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                :label="$t('m.out.sortingtype')"
                :label-width="formLabelWidth"
                prop="wavetemplateDto.sortingtype"
                align="left"
              >
                <el-select
                  :disabled="isdisabled"
                  clearable
                  v-model="formData.wavetemplateDto.sortingtype"
                  :placeholder="$t('m.choose')"
                >
                  <el-option
                    v-for="(item, index) in sortingtypeList"
                    :key="'sortingtype' + index"
                    :label="item.label"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="30">
            <el-col :span="12">
              <el-row>
                <el-col :span="16">
                  <el-form-item
                    style="margin-bottom: 0"
                    :label="$t('m.strategy.spustartnumber')"
                    :label-width="formLabelWidth"
                    prop="wavetemplateDto.spustartnumber"
                    align="left"
                  >
                    <el-input
                      @input="validateNumber('spustartnumber')"
                      maxlength="9"
                      show-word-limit
                      :disabled="isdisabled"
                      size="mini"
                      v-model.number="formData.wavetemplateDto.spustartnumber"
                      autocomplete="off"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="2" align="center">
                  <el-form-item>~</el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item
                    style="margin-bottom: 0"
                    prop="wavetemplateDto.spuendnumber"
                    align="left"
                  >
                    <el-input
                      @input="validateNumber('spuendnumber')"
                      maxlength="9"
                      show-word-limit
                      :disabled="isdisabled"
                      size="mini"
                      v-model.number="formData.wavetemplateDto.spuendnumber"
                      autocomplete="off"
                    ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="12">
              <el-row>
                <el-col :span="16">
                  <el-form-item
                    style="margin-bottom: 0"
                    :label="$t('m.strategy.skustarttotal')"
                    :label-width="formLabelWidth"
                    prop="wavetemplateDto.skustarttotal"
                    align="left"
                  >
                    <el-input
                      @input="validateNumber('skustarttotal')"
                      maxlength="9"
                      show-word-limit
                      :disabled="isdisabled"
                      size="mini"
                      v-model.number="formData.wavetemplateDto.skustarttotal"
                      autocomplete="off"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="2" align="center">
                  <el-form-item>~</el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item
                    style="margin-bottom: 0"
                    prop="wavetemplateDto.skuendtotal"
                    align="left"
                  >
                    <el-input
                      @input="validateNumber('skuendtotal')"
                      maxlength="9"
                      show-word-limit
                      :disabled="isdisabled"
                      size="mini"
                      v-model.number="formData.wavetemplateDto.skuendtotal"
                      autocomplete="off"
                    ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
          <el-row :gutter="30">
            <el-col :span="12">
              <el-row>
                <el-col :span="16">
                  <el-form-item
                    style="margin-bottom: 0"
                    :label="$t('m.strategy.starttotalmoney')"
                    :label-width="formLabelWidth"
                    prop="wavetemplateDto.starttotalmoney"
                    align="left"
                  >
                    <el-input
                      :disabled="isdisabled"
                      size="mini"
                      v-model="formData.wavetemplateDto.starttotalmoney"
                      autocomplete="off"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="2" align="center">
                  <el-form-item>~</el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item
                    style="margin-bottom: 0"
                    prop="wavetemplateDto.endtotalmoney"
                    align="left"
                  >
                    <el-input
                      :disabled="isdisabled"
                      size="mini"
                      v-model="formData.wavetemplateDto.endtotalmoney"
                      autocomplete="off"
                    ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
          <el-divider content-position="center"></el-divider>
        </el-form>
        <div class="btns">
          <el-button size="mini" @click="close">{{ $t("m.cancel") }}</el-button>
          <el-button
            v-if="btnControl == 0 || btnControl == 2"
            size="mini"
            type="primary"
            @click="save()"
            >{{ $t("m.confirm") }}</el-button
          >
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import common from '@/utils/common'
export default {
  data(){
    return {
      isdisabled:false,
      dialogFormVisible:false,
      treeLoading:false,
      tableData:[],
      formLabelWidth:'180px',
      formInline:{
        name:''
      },
      title:'',
      formData:{
        wavetemplateDto:{
          endtotalmoney:'',
          highvalue:null,
          orderquantity:null,
          ordertype:null,
          payment:null,
          platform:null,
          remark:'',
          skuendtotal:null,
          skustarttotal:null,
          sortingtype:null,
          spuendnumber:null,
          spustartnumber:null,
          starttotalmoney:'',
          state:null,
          wavetemplateid:null,
          wavetemplatename:''
        },
        consignors:[],
        regions:[],
        shops:[],
        warehouses:[]
      },
      popLoading:false,

      btnControl:0, //0:添加1：查看2：编辑
      provinceList:[],
      warehouseList:[],
      shopList:[],
      consignorList:[],
      consignors:[],
      shops:[],
      regions:[],
      warehouses:[],
      noData:0 //0代表所有数据都没选，不可以提交
    }
  },
  computed:{
    payList(){
      return [
        {
          id:1,
          label:this.$t('m.out.paytype1')
        },
        {
          id:2,
          label:this.$t('m.out.paytype2')
        }
      ]
    },
    platformList(){
      return [
        {
          id:1,
          label:'Zegobird'
        },
        {
          id:2,
          label:this.$t('m.in.other')
        }
      ]
    },
    highvalueList(){
      return [
        {
          id:1,
          label:this.$t('m.yes')
        },
        {
          id:0,
          label:this.$t('m.no')
        }
      ]
    },
    sortingtypeList(){
      return [
        {
          id:1,
          label:this.$t('m.out.pickingtype1')
        },
        {
          id:2,
          label:this.$t('m.out.pickingtype4')
        }
      ]
    },
    ordertypeList(){
      return [
        {
          id:1,
          label:this.$t('m.out.ordertype1')
        },
        {
          id:2,
          label:this.$t('m.out.ordertype2')
        }
      ]
    },
    ruleForm(){
      this.$nextTick(() => {
        this.$refs.refForm.clearValidate()
      })
      let checkSpu1 = (rule, value, callback) => {
        if (value){
          if (value < 1){
            callback(
              new Error(this.$t('m.enter') + this.$t('m.check.number0'))
            )
          }
          if (this.formData.wavetemplateDto.spuendnumber !== ''){
            this.$refs.refForm.validateField('wavetemplateDto.spuendnumber')
          }
          callback()
        } else {
          callback()
        }
      }
      let checkSpu2 = (rule, value, callback) => {
        if (value){
          if (value < 1){
            callback(
              new Error(this.$t('m.enter') + this.$t('m.check.number0'))
            )
          }
          if (value < this.formData.wavetemplateDto.spustartnumber){
            callback(new Error(this.$t('m.check.range')))
          } else {
            callback()
          }
        } else {
          callback()
        }
      }
      let checkSku1 = (rule, value, callback) => {
        if (value){
          if (value < 1){
            callback(
              new Error(this.$t('m.enter') + this.$t('m.check.number0'))
            )
          }
          if (this.formData.wavetemplateDto.skuendtotal !== ''){
            this.$refs.refForm.validateField('wavetemplateDto.skuendtotal')
          }
          callback()
        } else {
          callback()
        }
      }
      let checkSku2 = (rule, value, callback) => {
        if (value){
          if (value < 1){
            callback(
              new Error(this.$t('m.enter') + this.$t('m.check.number0'))
            )
          }

          if (value < this.formData.wavetemplateDto.skustarttotal){
            callback(new Error(this.$t('m.check.range')))
          } else {
            callback()
          }
        } else {
          callback()
        }
      }

      let checkPrice1 = (rule, value, callback) => {
        if (value){
          // if (parseFloat(value) <= 0){
          //   callback(
          //     new Error(this.$t('m.enter') + this.$t('m.check.number0'))
          //   )
          // }
          //输入之后触发endtotalmoney提交
          if (this.formData.wavetemplateDto.endtotalmoney !== ''){
            this.$refs.refForm.validateField('wavetemplateDto.endtotalmoney')
          }
          callback()
        } else {
          callback()
        }
      }
      let checkPrice2 = (rule, value, callback) => {
        if (value){
          // if (value <= 0){
          //   callback(
          //     new Error(this.$t('m.enter') + this.$t('m.check.number0'))
          //   )
          // }
          if (
            parseFloat(value) <
            parseFloat(this.formData.wavetemplateDto.starttotalmoney)
          ){
            callback(new Error(this.$t('m.check.range')))
          } else {
            callback()
          }
        } else {
          callback()
        }
      }
      return {
        wavetemplateDto:{
          endtotalmoney:[{ validator:checkPrice2, trigger:'blur' }],
          highvalue:null,
          orderquantity:[
            {
              required:true,
              message:this.$t('m.enter') + this.$t('m.check.count'),
              trigger:'blur'
            }
          ],
          skuendtotal:[{ validator:checkSku2, trigger:'blur' }],
          skustarttotal:[{ validator:checkSku1, trigger:'blur' }],
          sortingtype:null,
          spuendnumber:[{ validator:checkSpu2, trigger:'blur' }],
          spustartnumber:[{ validator:checkSpu1, trigger:'blur' }],
          starttotalmoney:[{ validator:checkPrice1, trigger:'blur' }],
          state:null,
          wavetemplateid:null,
          wavetemplatename:[
            {
              required:true,
              message:this.$t('m.enter') + this.$t('m.name'),
              trigger:'blur'
            }
          ]
        },
        warehouses:[
          {
            required:true,
            message:this.$t('m.choose') + this.$t('m.page.warehouse'),
            trigger:'change'
          }
        ]
      }
    }
  },
  methods:{
    positiveInt(key){
      if (this.formData.wavetemplateDto[key].toString().length === 1){
        this.$set(this.formData.wavetemplateDto, key, this.formData.wavetemplateDto[key].toString().replace(/[^1-9]/g, ''))
      } else {
        this.$set(this.formData.wavetemplateDto, key, this.formData.wavetemplateDto[key].toString().replace(/\D/g, ''))
      }
    },
    validateNumber(key){
      this.$set(this.formData.wavetemplateDto, key, this.formData.wavetemplateDto[key].toString().replace(/[^\d]/g, ''))
    },
    validateMoney(key){
      this.formData.wavetemplateDto[key] = this.formData.wavetemplateDto[key].toString().replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.').replace(/^(\\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^\./g, '')
    },
    init(){
      this.tableLoading = true
      this.$axios({
        method:'get',
        url:'/wavetemplate/page',
        params:{
          page:this.page,
          rows:this.rowSize,
          wavetemplatename:this.formInline.name
        }
      }).then(({ data }) => {
        for (let i = 0;i < data.records.length;i++){
          data.records[i].createdate = common.timestampToTime(
            data.records[i].createdate
          )
        }
        this.tableData = data.records
        this.totalRows = data.total
        setTimeout(() => this.tableLoading = false, 500)
      })
    },
    search(){
      this.page = 1
      this.init()
    },
    add(){
      this.isdisabled = false
      this.btnControl = 0;
      (this.title = this.$t('m.add') + this.$t('m.strategy.wavetemplate')),
      (this.dialogFormVisible = true)
      this.getConsignorList()
      this.getShopList()
      this.getWarehouseList()
      this.getProvinceList()
    },
    open(row){
      this.isdisabled = true
      this.btnControl = 1
      this.title = this.$t('m.strategy.wavetemplate')
      this.getInfoById(row.wavetemplateid)
      this.getConsignorList()
      this.getShopList()
      this.getWarehouseList()
      this.getProvinceList()
    },
    edit(row){
      this.isdisabled = false
      this.btnControl = 2
      this.title = this.$t('m.edit') + this.$t('m.strategy.wavetemplate')
      this.getInfoById(row.wavetemplateid)
      this.getShopList()
      this.getWarehouseList()
      this.getProvinceList()
    },
    close(){
      this.$refs['refForm'].resetFields()
      this.consignors = []
      this.shops = []
      this.regions = []
      this.warehouses = []
      this.dialogFormVisible = false
    },
    getConsignorList(){
      this
        .$axios({
          method:'get',
          url:'/consignor/list'
        })
        .then(({ data }) => {
          this.consignorList = data
          let consignorIds = this.consignorList.map((v) => {
            return v.consignorid
          })
          this.formData.consignors.forEach(v => {
            let index=consignorIds.indexOf(v.consignorid)
            if(index<0){
              this.consignorList.push(Object.assign({},{disabled:true},v))
            }
          })
        })
    },
    getWarehouseList(){
      let that = this
      that
        .$axios({
          method:'get',
          url:'/warehouse/list'
        })
        .then(({ data }) => {
          that.warehouseList = data
        })
    },
    getProvinceList(){
      this.$axios({
        method:'get',
        url:'/region/provincelist'
      }).then(({ data }) => {
        this.provinceList = data
      })
    },
    getShopList(){
      this.$axios({
        method:'get',
        url:'/shopinfo/list'
      }).then(({ data }) => {
        this.shopList = data
      })
    },
    remakeData(){
      let that = this
      let arr1 = []
      that.consignors.forEach(item => {
        arr1.push({
          consignorid:item,
          consignorname:that.consignorList.filter(i => {
            return i.consignorid === item
          })[0].consignorname,
          consignorcode:'123'
        })
      })

      that.formData.consignors = arr1

      let arr2 = []
      that.regions.forEach(item => {
        arr2.push({
          regionid:item,
          regionname:that.provinceList.filter(i => {
            return i.regionid === item
          })[0].regionname,
          level:1
        })
      })
      that.formData.regions = arr2

      let arr3 = []
      that.shops.forEach(item => {
        arr3.push({
          shopid:item,
          shopname:that.shopList.filter(i => {
            return i.shopid === item
          })[0].shopname,
          wavetemplateid:that.formData.wavetemplateDto.wavetemplateid
        })
      })
      that.formData.shops = arr3

      let arr4 = []
      that.formData.warehouses.forEach(item => {
        arr4.push({
          warehouseid:item,
          warehousename:that.warehouseList.filter(i => {
            return i.warehouseid === item
          })[0].warehousename
        })
      })
      that.formData.warehouses = arr4
    },
    save(){
      let that = this
      that.$refs['refForm'].validate(valid => {
        if (valid){
          //console.log(that.formData.consignors);
          that.checkData()
          if (that.noData === 1){
            that.remakeData()
            let url = ''
            let message = ''
            let method = ''
            if (that.btnControl === 0){
              url = '/wavetemplate/add'
              message = that.$t('m.success')
              method = 'post'
            }
            if (that.btnControl === 2){
              url = '/wavetemplate/update'
              message = that.$t('m.editSuccess')
              method = 'put'
            }
            that
              .$axios({
                method:method,
                url,
                data:{ ...that.formData }
              })
              .then(() => {
                that.$message({
                  showClose:true,
                  message:message,
                  type:'success',
                  duration:1500
                })
                that.init(1, 10)
                that.dialogFormVisible = false

              })
          }
        }
      })
    },
    getInfoById(id){
      let that = this
      that.clickId = id
      that.popLoading = true
      that.dialogFormVisible = true
      that
        .$axios({
          method:'get',
          url:`/wavetemplate/${id}`
        })
        .then(({ data }) => {
          that.formData = data
          that.formData.consignors.forEach(item => {
            that.consignors.push(item.consignorid)
          })
          that.formData.regions.forEach(item => {
            that.regions.push(item.regionid)
          })
          that.formData.shops.forEach(item => {
            that.shops.push(item.shopid)
          })
          that.formData.warehouses.forEach(item => {
            that.warehouses.push(item.warehouseid)
          })
          that.formData.warehouses = that.warehouses

          that.popLoading = false
          that.getConsignorList()
        })
    },
    changeState(id, index, state){
      this.$axios({
        method:'put',
        url:`/wavetemplate/${id}/state`,
        params:{
          state:state
        }
      }).then(() => {
        this.tableData[index].state = state
      })
    },
    checkData(){
      let that = this
      if (
        that.consignors.length < 1 &&
        that.shops.length < 1 &&
        that.regions.length < 1 &&
        !that.formData.wavetemplateDto.payment &&
        !that.formData.wavetemplateDto.platform &&
        !that.formData.wavetemplateDto.highvalue &&
        !that.formData.wavetemplateDto.ordertype &&
        !that.formData.wavetemplateDto.sortingtype &&
        !that.formData.wavetemplateDto.spustartnumber &&
        !that.formData.wavetemplateDto.spuendnumber &&
        !that.formData.wavetemplateDto.skustarttotal &&
        !that.formData.wavetemplateDto.skuendtotal &&
        !that.formData.wavetemplateDto.starttotalmoney &&
        !that.formData.wavetemplateDto.endtotalmoney
      ){
        that.noData = 0
        return that.$message({
          showClose:true,
          message:that.$t('m.strategy.least'),
          type:'error',
          duration:1500
        })
      } else {
        that.noData = 1
      }
    }
  },
  activated(){
    this.init()
  },
  watch:{
    'formData.wavetemplateDto.starttotalmoney'(newVal){
      if (newVal){
        this.formData.wavetemplateDto.starttotalmoney = newVal.toString().replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.').replace(/^(\\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^\./g, '')
      }
    },
    'formData.wavetemplateDto.endtotalmoney'(newVal){
      if (newVal){
        this.formData.wavetemplateDto.endtotalmoney = newVal.toString().replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.').replace(/^(\\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^\./g, '')
      }
    }
  },
  beforeRouteLeave(to, form, next){
    this.dialogFormVisible = false
    next()
  }
}
</script>
<style lang="scss" scoped>
.el-table .el-form-item {
  margin-bottom: 0;
}
.el-select {
  width: 100%;
}
</style>